package com.lsk.task;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.lsk.util.Syslog;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 配置代理商返利率
 */
public class AgentTask implements Runnable{
    private String memberId;

    public AgentTask(){}
    public AgentTask(String memberId){
        this.memberId=memberId;
    }

    @Override
    public void run() {
        if (StringUtils.isNotBlank(memberId)){


            String memberSql="select *from yx_member where id='"+memberId+"'";

            Record member=Db.findFirst(memberSql);

            String sql="select id,discount from commodity_facevalue " +
                    "where commodityId in (SELECT id from commodity WHERE type='"+member.getStr("type")+"')";

            List<Record> list=new ArrayList<>();

            List<Record> facevalueList = Db.find(sql);

            for (Record record:facevalueList){//yx_member_rebates
                Record insetRecord = new Record().set("memberId", memberId)
                        .set("faceValueId", record.getStr("id")).set("rebatesThan", 0.00);
                list.add(insetRecord);
            }

            Db.batchSave("yx_member_rebates",list,list.size());

        }else{

        }
    }
}
